//
//  RMMMineMyWalletViewController.m
//  Romomo
//
//  Created by puman on 2016/12/28.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMMineMyWalletViewController.h"
#import "RMMMineMyWalletView.h"
#import "RMMMyWalletTableViewCell.h"
#import "RMMMemberCardViewController.h"
#import "RMMYouHuiQuanViewController.h"

@interface RMMMineMyWalletViewController ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation RMMMineMyWalletViewController
{
    RMMMineMyWalletView *_myWalletView;
    UITableView *_tableView;
    NSArray *_imageArray;
    NSArray *_titleArray;
    NSArray *_contentArray;
    NSDictionary *_dic;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self getData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我的钱包";
    self.view.backgroundColor = kCColor;
    [self addSubViews];
    // Do any additional setup after loading the view.
}
- (void)getData{
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    parDic[@"org_no"] = Org_no;
    parDic[@"cust_id"] = [[RMMFileManager shareHandle].userDic objectForKey:@"CUST_ID"];
    NSString *url = GetMeberDetailUrl;
    [OSRequestManager requestWithUrlString:url parDic:parDic method:GET finish:^(NSDictionary *dataDic) {
        NSString *status = [NSString stringWithFormat:@"%@",dataDic[@"status"]];
        if ([status isEqualToString:@"1"]) {
            _dic = [RMMFileManager setValueForDic:dataDic[@"data"]];
            _contentArray = @[[NSString stringWithFormat:@"¥%.2f",[_dic[@"BALANCE"] floatValue]],[NSString stringWithFormat:@"%@张",_dic[@"VOUCHER_COUNT"]],[NSString stringWithFormat:@"%@分",_dic[@"AVA_POINTS"]]];
            _myWalletView.dataDic = _dic;
        } else {
            [RMMFileManager MBProgressWith:dataDic[@"message"] onView:self.view];
        }
        [_tableView reloadData];
    } error:^(NSError *errors) {
        
    } view:self.view];
}
- (void)addSubViews{
    _myWalletView = [[RMMMineMyWalletView alloc] initWithFrame:CGRectMake(0, 0, kScreenWideth, 240)];
    [self.view addSubview:_myWalletView];
    
    _imageArray = @[@"会员卡@3x",@"券@3x",@"颜值@3x"];
    _titleArray = @[@"会员卡",@"优惠券",@"剩余颜值"];
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, _myWalletView.bottom, self.view.width, 162) style:(UITableViewStylePlain)];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWideth, 0)];
    [_tableView registerClass:[RMMMyWalletTableViewCell class] forCellReuseIdentifier:@"Cell"];
    [self.view addSubview:_tableView];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 54;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RMMMyWalletTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.imageV.image = [UIImage imageNamed:_imageArray[indexPath.row]];
    cell.titleLabel.text = _titleArray[indexPath.row];
    cell.contentLabel.text = _contentArray[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        RMMMemberCardViewController *VC = [[RMMMemberCardViewController alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
    } else if (indexPath.row == 1) {
        RMMYouHuiQuanViewController *VC = [[RMMYouHuiQuanViewController alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
    } else {
        
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
